package lxn;

import static org.junit.Assert.assertEquals;
import robocode.control.testing.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots.
 * This test simply verifies that Obon always beats SittingDuck.
 * Code Mostly borrowed from TestDaCruzerVersusSittingDuck class.
 * 
 * @author Leonardo Nguyen
 * @version Java 1.6.0_21
 */
public class TestObonVersusSittingDuck extends RobotTestBed {

  /**
   * Specifies that SittingDuck and DaCruzer are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override public String getRobotNames() {
    return "sample.SittingDuck,lxn.Obon";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override public int getNumRounds() {
    return 10;
  }
  
  /**
   * The actual test, which asserts that Obon has won every round against SittingDuck.
   * @param event Details about the completed battle.
   */
  @Override public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    // Sanity check that results[1] is Obon (not strictly necessary, but illustrative).
    BattleResults obonResults = battleResults[1];
    String robotName = obonResults.getTeamLeaderName();
    assertEquals("Check that results[1] is Obon", robotName, "lxn.Obon*");
    
    // Checks to make sure Obon won every round.
    assertEquals("Check Obon winner", obonResults.getFirsts(), getNumRounds());
  }
}
